package Application.Components.Schedule;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;

import Interfaces.IDrawableComponent;

/**
 * 
 * @author vit.terl
 *
 */
public class Lesson implements IDrawableComponent {
	public static final float X_OFFSET_CLASSES	=	20.0f;	//1/20.0f of width
	public static final float Y_OFFSET_CLASSES	=	20.0f;	//1/20.0f of height
	
	
	private String teacher;
	private String lessonName;
	private String classes;
	
	public Lesson(String teacher, String lessonName, String classes){
		this.lessonName 	= lessonName;
		this.teacher 		= teacher;
		this.classes		= classes;
	}
	
	public void fromString(String s){
		String[] tmp = s.split(",");
		
		lessonName = tmp[1];
		classes = tmp[2];
		teacher = tmp[3];
	}
	
	@Override
	public void draw(Graphics g) {
		g.setFont(new Font("monospaced", Font.BOLD, 45));
		g.setColor(Color.green);
		g.drawString(teacher, 45, 45);
	}
	
	public void draw(Graphics g, int x, int y, int width, int height){
		if(lessonName.isEmpty()) g.setColor(Schedule.COLOR_PASSIVE_LESSON);
		else	g.setColor(Schedule.COLOR_ACTIVE_LESSON);
		
		g.fillRect(x, y, width, height);
		
		g.setColor(Color.BLACK);
		g.drawRect(x, y, width, height);
		
		/**
		 * Drawing classes
		 */
		
		g.setFont(new Font("arial", Font.BOLD, (int)(height/5.0f)));
		g.drawString(classes, (int)(x+(width/X_OFFSET_CLASSES)), (int)(y + height - (height/Y_OFFSET_CLASSES)) );
		
		/**
		 * Drawing lessonName
		 */
		Font font = new Font("arial", Font.BOLD, (int)(height/2.5f));
		FontMetrics fm		= g.getFontMetrics(font);
		
		float textWidth 	= (float)fm.getStringBounds(lessonName, g).getWidth();
		
		int textX = (int)( (width - textWidth)/2 );
	
		g.setColor(Color.BLACK);
		g.setFont(font);
		g.drawString(lessonName, x + textX,y + (int)(height/10.0f * 4));
		
		/**
		 * Drawing teacherName
		 */
		
		font	= new Font("arial", Font.BOLD, (int)(height/4.0f));
		fm		= g.getFontMetrics(font);
	
		textWidth 	= (float)fm.getStringBounds(teacher, g).getWidth();
		
		textX = (int)( (width - textWidth)/2 );
		
		g.setColor(Color.BLACK);
		g.setFont(font);
		g.drawString(teacher, x + textX,y + (int)(height/10.0f * 7));
	}
}
